#!/usr/bin/python3

import secrets_info
import openai

def chat():
    # 设置API密钥
    api_key = secrets_info.GPT4_API_KEY
    openai.api_base = secrets_info.GPT4_URL_BASE

    model="gpt-3.5-turbo-0613"
    openai.api_key = api_key

    system = '你是一个擅长编写代码的技术专家'
    conversation_history = [{"role": "system", "content": system}]

    while True:
        user_input = input("User: ")
        if user_input.lower() == "quit":
            break

        conversation_history.append({"role": "user", "content": user_input})

        # 调用OpenAI ChatCompletion.create函数进行对话生成
        response = openai.ChatCompletion.create(
            model=model,
            messages=conversation_history
        )

        # 获取AI回复
        ai_reply = response['choices'][0]['message']['content']
        # 打印AI回复
        print(f"AI: {ai_reply}")
        print("================================")


chat()
